
package eu.jpereira.trainings.designpatterns.structural.decorator.channel.decorator;

import eu.jpereira.trainings.designpatterns.structural.decorator.channel.SocialChannel;

public class WordCensor extends SocialChannelDecorator {

	String CensoredWord;
	
	public WordCensor(String CensoredWord) {
		this.CensoredWord = new String(" "+CensoredWord +" ");
	}

	
	public WordCensor(String CensoredWord, SocialChannel channel) {
		this.CensoredWord = new String(" "+CensoredWord +" ");
		this.delegate = channel;
	}
	
	@Override
	public void deliverMessage(String message) {
		message = message.replaceAll(CensoredWord, " ### ");
		if (delegate != null) {
			delegate.deliverMessage(message);
		}
		
	}

	
}

